﻿using System;
using System.IO;
using System.Xml;
using System.Configuration;
using System.Web;
using SyCODE.Component.DataFactory;
using System.Collections.Specialized;

/// <summary>
/// SyCODE 的摘要说明
/// </summary>
namespace SyCODE.Blog.DataReader
{
    /// <summary>
    /// PublicHandler 的摘要说明
    /// </summary>
    public class GetHandler : IHttpHandler
    {
        #region IHttpHandler 成员

        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            context.Response.Expires = 120;
            context.Response.ContentType = "text/xml";

            DBAM dbam = new DBAM();
            dbam.BuildParameters(context.Request.QueryString["ds"], context.Request.QueryString, false);

            XmlTextWriter writer = new XmlTextWriter(context.Response.OutputStream, context.Response.ContentEncoding);
            writer.WriteStartDocument();

            if (!String.IsNullOrEmpty(context.Request.QueryString["ui"]))
            {
                writer.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='/ui/common/" + context.Request.QueryString["ui"] + ".xsl'");
            }
            try
            {
                dbam.ExecuteXmlTextWriter(writer, context.Request.QueryString);
            }
            finally
            {
                dbam.Dispose();
            }

            writer.WriteEndDocument();

            writer.Flush();
        }
        #endregion
    }
}